<!DOCTYPE html>
<!-- This is an example app used by chrome/functional/apptest.py to demonstrate
     use of the Automation Event Queue for testing webapps using DomMutation
     observers.

     This example webapp simulates an asyncronous login flow. -->
<html>

  <head>
    <title>AppTest Example</title>
    <script type="text/javascript">
      var globalTimeout;

      function write(str) {
        document.getElementById("console").innerHTML += "> " + str + "<br \>";
      }

      /* Calls a function after a specified number of miliseconds. */
      function delayedCallback(f, ms) {
        globalTimeout = setTimeout(f, ms);
      }

      function init() {
        write("Initializing...");
        delayedCallback(createLoginLink, 2000);
      }

      function createLoginLink() {
        write("<a id='login' href='' onclick='return login();'>Log In</a>");
      }

      function login() {
        write("Logging in...");
        delayedCallback(loginSuccess, 2000);
        return false;
      }

      function loginSuccess() {
        write("Login succeeded!");
        document.getElementById("fail").innerHTML = "";
      }

      function fail() {
        clearTimeout(globalTimeout);
        write("App failed!");
        return false;
      }
    </script>
  </head>

  <body onload="init()">
    <div id="fail">
      [ <a href='' onclick='return fail();'>Fail Test</a> ]
      <br /><br />
    </div>

    <div id="console">
    </div>

  </body>

</html>
